package com.gxk.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.GL30;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.gxk.game.FlappyBird;
import com.gxk.res.PublicConst;
import com.gxk.stage.LoadingStage;

public class LoadingScreen extends ScreenAdapter {
	private FlappyBird game;
	private float stateTime;
	private Viewport viewport;
	private Stage loginStage;

	public LoadingScreen(FlappyBird flappyBird) {
		this.game = flappyBird;
		loginStage = new LoadingStage();
		this.setViewPort();
	}

	private void setViewPort() {
		Gdx.graphics.setDisplayMode(PublicConst.WORLD_WIDTH,
				PublicConst.WORLD_HEIGHT, false);
		viewport = loginStage.getViewport();
		viewport.setWorldSize(PublicConst.WORLD_WIDTH, PublicConst.WORLD_HEIGHT);
		viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
		loginStage.setViewport(viewport);
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
		
		loginStage.act();
		loginStage.draw();
		
		stateTime +=Gdx.graphics.getDeltaTime();
		if (stateTime>3) {
			game.setScreen(game.getPreScreen());
			System.out.println("screen changed");
		}
		super.render(delta);
	}

}
